import { defineStore } from 'pinia'
import { roleApi, permissionApi } from '@/api'

export const usePermissionStore = defineStore('permission', {
  state: () => ({
    roles: [],
    permissions: []
  }),
  actions: {
    async getRoles() {
      try {
        const response = await roleApi.getAllRoles()
        this.roles = response.data || response || []
      } catch (error) {
        console.error('获取角色列表失败:', error)
        this.roles = []
      }
    },
    async getPermissions() {
      try {
        const response = await permissionApi.getAllPermissions()
        this.permissions = response.data || response || []
      } catch (error) {
        console.error('获取权限列表失败:', error)
        this.permissions = []
      }
    }
  }
})